package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"io/ioutil"
	"net/http"
)

func main() {

	r := gin.Default()
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})
	r.GET("/test", func(context *gin.Context) {
		c := make(chan string)
		go Get("http://www.baidu.com", c)
		str := <-c
		context.Writer.WriteString(str)
	})

	r.GET("/s", func(context *gin.Context) {
		c := make(chan string)
		go GetForParams("http://www.baidu.com", context.Params, c)

		str := <-c

		fmt.Println("uri = ", context.Request.RequestURI)
		context.Writer.WriteString(str)
	})
	r.Run() // listen and serve on 0.0.0.0:8080

}

func Get(url string, c chan string) {
	resp, _ := http.Get(url)
	bytes, _ := ioutil.ReadAll(resp.Body)
	c <- string(bytes)
}

func GetForParams(url string, params gin.Params, c chan string) {

}
